package com.dingding.core.special.service.impl;

import javax.annotation.Resource;

import org.apache.http.HttpStatus;
import org.springframework.stereotype.Component;

import com.dingding.common.core.base.dto.ResponseEntity;
import com.dingding.common.core.beans.special.Specialuserlogin;
import com.dingding.common.core.util.ToolUtil;
import com.dingding.core.special.dao.ISpecialDepositPasswordDao;
import com.dingding.core.special.service.ISpecialDepositPasswordService;
import com.dingding.facade.user.common.dto.special.driver.ReqForgetSpecialDepositPassword;
import com.dingding.facade.user.common.dto.special.driver.ReqUpdateSpecialDepositPassword;

/**
 * 
 * @ClassName: SpecialDepositPasswordServiceImpl 
 * @Description: 专车用户提现密码业务逻辑实现类
 * @author YHQ
 * @date 2016年12月22日 上午11:46:01
 * @since V2.6.3
 * 
 */
@Component("specialDepositPasswordService")
public class SpecialDepositPasswordServiceImpl implements ISpecialDepositPasswordService{

	@Resource(name = "specialDepositPasswordDao")
	private ISpecialDepositPasswordDao specialDepositPasswordDao;
	
	/**
	 * 
	 * @Title: updateSpecialDepositPassword 
	 * @Description: 修改用户提现密码(司机端)
	 * @param reqUpdateSpecialDepositPassword 修改用户提现密码客户端请求Bean
	 * @author YHQ 
	 * @return ResponseEntity<Object>
	 * 
	 */
	@Override
	public ResponseEntity<Object> updateSpecialDepositPassword(ReqUpdateSpecialDepositPassword reqUpdateSpecialDepositPassword) {
		
		ResponseEntity<Object> responseEntity = new ResponseEntity<Object>();
		
		// 客户端请求参数
		if(reqUpdateSpecialDepositPassword == null || !ToolUtil.validateParam(reqUpdateSpecialDepositPassword)){
			
			responseEntity.setCode(HttpStatus.SC_BAD_REQUEST);
			responseEntity.setErrorMessage("客户端请求参数为空");
			responseEntity.setPromptMessage("请求参数异常");
			
			return responseEntity;
		}
		
		// 根据用户Id获取专车用户信息
		Specialuserlogin specialuserlogin = specialDepositPasswordDao.getSpecialUserLogin(reqUpdateSpecialDepositPassword.getUserId());
		
		if(specialuserlogin != null && ToolUtil.isNotBlank(specialuserlogin.getDepositPwd())){
			
			if(reqUpdateSpecialDepositPassword.getUsedPassword().equals(specialuserlogin.getDepositPwd())){
				
				// 修改用户提现密码(司机端)
				boolean flag = specialDepositPasswordDao.updateSpecialUserDepositPassword(reqUpdateSpecialDepositPassword.getUserId(), reqUpdateSpecialDepositPassword.getNewPassword());
				
				if(flag){
					responseEntity.setCode(HttpStatus.SC_OK);
				}else{
					responseEntity.setCode(HttpStatus.SC_BAD_REQUEST);
					responseEntity.setErrorMessage("修改用户提现密码失败");
					responseEntity.setPromptMessage("修改用户提现密码失败");
				}
				
				return responseEntity;
			}else{
				responseEntity.setCode(HttpStatus.SC_BAD_REQUEST);
				responseEntity.setErrorMessage("原密码输入有误");
				responseEntity.setPromptMessage("原密码输入有误");
			}
			
		}else{
			responseEntity.setCode(HttpStatus.SC_BAD_REQUEST);
			responseEntity.setErrorMessage("该用户不存在或者提现密码未设置");
			responseEntity.setPromptMessage("该用户不存在或者提现密码未设置");
		}
		
		return responseEntity;
	}

	/**
	 * 
	 * @Title: forgetSpecialDepositPassword 
	 * @Description: 忘记提现密码(司机端) 
	 * @param reqForgetSpecialDepositPassword 忘记提现密码客户端请求Bean
	 * @author YHQ 
	 * @since V2.6.3
	 * @return ResponseEntity<Object>    返回类型
	 * 
	 */
	@Override
	public ResponseEntity<Object> forgetSpecialDepositPassword(ReqForgetSpecialDepositPassword reqForgetSpecialDepositPassword) {
		
		ResponseEntity<Object> responseEntity = new ResponseEntity<Object>();
		
		// 判断客户端请求参数是否为空
		if(reqForgetSpecialDepositPassword == null || !ToolUtil.validateParam(reqForgetSpecialDepositPassword)){
			
			responseEntity.setCode(HttpStatus.SC_BAD_REQUEST);
			responseEntity.setErrorMessage("客户端请求参数为空");
			responseEntity.setPromptMessage("请求参数异常");
			
			return responseEntity;
		}
		
		// 忘记提现密码(司机端)
		boolean flag = specialDepositPasswordDao.updateSpecialUserDepositPassword(reqForgetSpecialDepositPassword.getUserId(), reqForgetSpecialDepositPassword.getNewPassword());
		
		if(flag){
			responseEntity.setCode(HttpStatus.SC_OK);
		}else{
			responseEntity.setCode(HttpStatus.SC_BAD_REQUEST);
			responseEntity.setErrorMessage("重置忘记的提现密码失败");
			responseEntity.setPromptMessage("重置忘记的提现密码失败");
		}
		
		return responseEntity;
	}

}
